package com.base.cn.platform.os.controller.agent.income;

import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.course.agent.income.AgentIncomeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 收益明细接口Controller
 *
 * @author s.li
 * @create 2018-09-26-18:32
 */
@RestController
@RequestMapping("/api/agent/income")
public class ApiAgentIncomeInfoController extends ApiBaseController {

    @Autowired
    private AgentIncomeInfoService agentIncomeInfoService;

    /**
     * 用户收益明细列表
     * @param agentUserId 推广员ID
     * @param currentPage 页码
     * @param beginPayTime 开始支付时间
     * @param endPayTime 结束支付时间
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return Map<String,Object>
     */
    @RequestMapping("/queryIncomeInfoList")
    public Map<String,Object> queryIncomeInfoList(@RequestParam("agentUserId") BigDecimal agentUserId,
                                                  @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage,
                                                  @RequestParam(value = "beginPayTime",required = false) String beginPayTime,
                                                  @RequestParam(value = "endPayTime",required = false) String endPayTime,
                                                  @RequestParam(value = "startTime",required = false) String startTime,
                                                  @RequestParam(value = "endTime",required = false) String endTime){
        Map<String,Object> params = new HashMap<>();
        params.put("beginPayTime",beginPayTime);
        params.put("endPayTime",endPayTime);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("agentUserId", agentUserId);
        Map<String, Object> dataMap = agentIncomeInfoService.queryIncomeInfoListPage(currentPage, params, true, true);
        return ResultUtil.SUCCESS(dataMap);
    }

    /**
     * 查看结算周期下的收益明细
     * @param settlementId 周期ID
     * @param currentPage 页码
     * @return
     */
    @RequestMapping("/settlementInfoList")
    public Map<String,Object> settlementInfoList(@RequestParam("settlementId") BigDecimal settlementId,
                                                 @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        Map<String,Object> params = new HashMap<>();
        params.put("settlementId",settlementId);
        Map<String,Object> dataMap = agentIncomeInfoService.queryIncomeInfoListPage(currentPage,params,true,true);
        return ResultUtil.SUCCESS(dataMap);
    }

    /**
     * 计算可结算的收益总金额
     * @param userId 用户ID
     * @return Map<String,Object>
     */
    @RequestMapping("/countAvailableIncome")
    public Map<String,Object> countAvailableIncome(@RequestParam("userId") BigDecimal userId){
        double sumPrice = agentIncomeInfoService.countAvailableIncome(userId);
        return ResultUtil.SUCCESS(sumPrice);
    }
}
